package UI.MultiPlayer;
import org.jfree.layout.CenterLayout;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Panel;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStreamImpl;
import javax.swing.*;

/**
 * @author 杨明政
 * @version  2021.0520
 * @since 1.8
 */


/**
 * 图片预览类.
 * For example:
 * <pre>
 * GraphDisplay u=new GraphDisplay();
 * u.display(aimFile)
 * </pre>
 * @author 杨明政
 * @see javax.swing.JComponent
 * @see javax.swing.JPanel
 */
public class GraphDisplay {
    public static JFrame disWindow;
    /**
     * 展示所选中的图片
     * @param aimFile 目标图片文件
     */
    public static void disPlay(String aimFile)
    {
        disWindow=new JFrame("picture view");
        disWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        disWindow.setVisible(true);
        disWindow.setBounds(600,200,700,555);
        BufferedImage img=null;
        try {
            img= ImageIO.read(new File(aimFile));
        } catch (IOException e) {
            e.printStackTrace();
        }
        disWindow.getContentPane().setLayout(new CenterLayout());
        JLabel lable=new JLabel(new ImageIcon(img));
        disWindow.getContentPane().add(lable);
        int midx=(disWindow.getContentPane().getWidth()-img.getWidth())/2;
        int midy=(disWindow.getContentPane().getHeight()-img.getHeight())/2;
        int with= Math.min(img.getWidth(), 700);
        int height= Math.min(img.getHeight(), 555);
        lable.setBounds(midx,midy,with,height);
    }
}
